from task_planner.srv import *
import rospy

# The Actions object define which were the lasted actions performed
class Actions:

	# class attributes	
	a_TurnOnLight = False
	a_TurnOffLight = True	
	a_TurnOnBlinds = False		
	a_Auto2Manual = False
	a_Manual2Auto = True
		
	# print method	
	def __str__(self): 
		a0 = '\n # ACTIONS STATUS: \n' 
		a1 = '  - a_TurnOnLight =  ' + str(self.a_TurnOnLight) + '\n'
		a2 = '  - a_TurnOffLight = ' + str(self.a_TurnOffLight) + '\n'
		a3 = '  - a_TurnOnBlinds = ' + str(self.a_TurnOnBlinds) + '\n'
		a4 = '  - a_Auto2Manual = ' + str(self.a_Auto2Manual) + '\n'
		a5 = '  - a_Manual2Auto = ' + str(self.a_Manual2Auto) + '\n'		
		return a0+a1+a2+a3+a4+a5
	
	# Switch on the blinds
	def TurnOnBlinds(self,env):
		if (env.p_BlindsON == False) and (env.p_Presence == True):
			self.a_TurnOnBlinds = True
		    
			rospy.wait_for_service('/environment/set_BlindsON')
			try:
				set_BlindsON = rospy.ServiceProxy('/environment/set_BlindsON', SetBool)
				set_BlindsON(True)
				
			except rospy.ServiceException, e:
				print "Service call 1 failed: %s" % e
	
	
	# Switch on the light
	def TurnOnLight(self,env):
		if (env.p_LightON == False) and (env.p_Presence == True):
			
			self.a_TurnOnLight  = True
			self.a_TurnOffLight = False
			
			rospy.wait_for_service('/environment/set_LightON')	
			try:
				set_LightON = rospy.ServiceProxy('/environment/set_LightON', SetBool)
				set_LightON(True)
					
			except rospy.ServiceException, e:
				print "Service call 2 failed: %s" % e
			
	# Switch off the light
	def TurnOffLight(self,env):
		if (env.p_LightON == True) and (env.p_Presence == False):
			self.a_TurnOffLight = True
			self.a_TurnOnLight  = False
			env.p_LightON       = False
	
	# Change in Automatic mode
	def Manual2Auto(self,env):
		if (env.p_AutoMode == False) and (env.p_Presence == False):
			self.a_Manual2Auto = True
			self.a_Auto2Manual = False
			env.p_AutoMode     = True
	
	# Change Manual mode
	def Auto2Manual(self,env):
		if (env.p_AutoMode == True) and ((env.p_LightButton == True) or (env.p_BlindsButton == True)):
			self.a_Auto2Manual = True
			self.a_Manual2Auto = False
			env.p_AutoMode     = False
		
	
	
	
		
